package com.example.neusoft.yuejian.Activity;

;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.neusoft.yuejian.Base.BaseActivity;
import com.example.neusoft.yuejian.Base.BaseListener;
import com.example.neusoft.yuejian.Base.BaseModel;
import com.example.neusoft.yuejian.Bean.ActBean;
import com.example.neusoft.yuejian.Bean.ActDetailBean;
import com.example.neusoft.yuejian.Bean.ClubDetailBean;
import com.example.neusoft.yuejian.Bean.CollectionBean;
import com.example.neusoft.yuejian.Bean.GuanzhuBean;
import com.example.neusoft.yuejian.R;
import com.squareup.picasso.Picasso;

import retrofit2.Call;

public class ActDetailActivity extends BaseActivity implements View.OnClickListener {
    private ActDetailBean act;
    private TextView hdmc, hdsj, fbsj, hddz, hdxq;
    private ImageView tp,act_fh,sc;
    private Button bm;
    private int id,uid;
    private SharedPreferences sp1 ;

    @Override
    public int getLayoutFile() {
        return R.layout.act_detail;


    }

    @Override
    public void initView() {
        hdmc = (TextView) findViewById(R.id.hdmc);
        hddz = (TextView) findViewById(R.id.hddz);
        hdxq = (TextView) findViewById(R.id.hdxq);
        fbsj = (TextView) findViewById(R.id.fbsj);
        hdsj = (TextView) findViewById(R.id.hdsj);
        tp = (ImageView) findViewById(R.id.tp);
        bm = (Button) findViewById(R.id.bm);
        act_fh=(ImageView)findViewById(R.id.act_fh);
        sc=(ImageView)findViewById(R.id.sc);

    }

    @Override
    public void initEvent() {
        bm.setOnClickListener(this);
        act_fh.setOnClickListener(this);
        sc.setOnClickListener(this);
    }

    @Override
    public void initData() {
        Intent intent=getIntent();
        int id=intent.getIntExtra("aid",0);
        sp1=ActDetailActivity.this.getSharedPreferences("User", ActDetailActivity.this.MODE_PRIVATE);
        uid= sp1.getInt("id",0);

        getactdetail(id,uid);}


        private void getactdetail(int id,int uid){
            BaseModel<ActDetailBean>model=new BaseModel<>();
            Call<ActDetailBean>call=model.service.actDetail(id,uid);
            model.callEnqueue(call,list);
        }

        BaseListener<ActDetailBean> list=new BaseListener<ActDetailBean>() {
            @Override
            public void onResponse(ActDetailBean actDetailBean) {
                act=actDetailBean;
                hdmc.setText(act.getAname());
                hdsj.setText(act.getAstarttime());
                fbsj.setText(act.getAaddtime());
                hdxq.setText(act.getAintro());
                hddz.setText(act.getAaddress());
                id=act.getAid();

                Picasso.with(ActDetailActivity.this).load("http://10.0.2.2/YueJian/public/static/img/" +
                        act.getApic()).into(tp);
            }

            @Override
            public void onFail(String msg) {
                showToast("获取精彩活动详情失败");
            }
        };

    private void getsc(int id,int uid){
        BaseModel<CollectionBean> model=new BaseModel<>();
        Call<CollectionBean> call=model.service.getcollection( id, uid);
        model.callEnqueue(call,list5);
    }
    BaseListener<CollectionBean> list5=new BaseListener<CollectionBean>() {
        @Override
        public void onResponse(CollectionBean collectionBean) {
            if(collectionBean.getStatus()==1){
                sc.setImageResource(R.drawable.ic_xin1);
                showToast(collectionBean.getMessage());

            }else{
                showToast(collectionBean.getMessage());

            }
        }

        @Override
        public void onFail(String msg) {
            showToast("111");
        }
    };

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bm:
                Intent intent = new Intent(this, ActEnrollActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("aid", act);
                intent.putExtras(bundle);
                startActivity(intent);
                break;
            case R.id.act_fh:
                finish();
                break;
            case R.id.sc:
                getsc(id,uid);
        }
    }
}

